home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / fontutil.6 / fontutil / fontutils-0.6 / lib / float-ok.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-07  |  1.4 KB  |  61 lines

  1. /* float-ok.c: test if a string is a valid floating-point number.
  2.  
  3. Copyright (C) 1992 Free Software Foundation, Inc.
  4.  
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9.  
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  18.  
  19. #include "config.h"
  20.  
  21. #include <ctype.h>
  22.  
  23.  
  24. /* Actually, we don't worry about a trailing exponent.  */
  25.  
  26. boolean
  27. float_ok (string str)
  28. {
  29.   boolean found_digit = false;
  30.   
  31.   if (str == NULL)
  32.     return false;
  33.     
  34.   /* Allow leading `-' or `+' sign (but digits must follow).  */
  35.   if (*str == '-' || *str == '+')
  36.     {
  37.       str++;
  38.     }
  39.   
  40.   /* Skip decimal digits.  */
  41.   while (isdigit (*str))
  42.     {
  43.       str++;
  44.       found_digit = true;
  45.     }
  46.   
  47.   /* If a `.' follows, can have more digits.  */
  48.   if (*str == '.')
  49.     {
  50.       str++;
  51.       while (isdigit (*str))
  52.         {
  53.           str++;
  54.           found_digit = true;
  55.     }
  56.     }
  57.   
  58.   return *str == 0 && found_digit;
  59. }
  60.  
  61.